package com.itxuhang.mvc.mapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class SimpleUrlHandlerMapping implements HandlerMapping{

    private Map<String,Object> urlHandlers = new HashMap<>();

    public SimpleUrlHandlerMapping(){
        // 建立uri和handler的映射
//        urlHandlers.put("/queryUser",new QueryUserHandler());
//        urlHandlers.put("/saveUser",new SaveUserHandler());
    }

    //根据请求URI查找对应的handler
    @Override
    public Object getHandler(HttpServletRequest request){
        String uri = request.getRequestURI();
        if(uri == null || uri.equals("")){
            return null ;
        }
        return this.urlHandlers.get(uri);
    }
}
